<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>假店假货登记</title>
<script type="text/javascript" src="../boot.js"></script>
<script>
var tbgrid=null;
var myform=null;
function parsePage(){

$('#toolbar').toolbar({
	items: [{
				text : '新增',
				iconCls : 'icon-add',
				handler : function() {
					add();
				}
			}, '-', {
				text : '删除',
				iconCls:'icon-del',
				handler : function() {
					var node = tbgrid.datagrid('getChecked');
					var ids=[];
					$.each(node,function(index,val){
						ids.push(val.id);
					});
					del(ids);
				}
			}] 
});



tbgrid = $('#tbList').datagrid({
			data:{"total":1,"rows":[{'id':1,'col1':'假店店铺','col2':'深圳特级运动专卖店','col3':'http://www.baidu.com','col4':'店铺装修','col5':'2011-8-3 12:00:00','col6':'张三','col7':0,'col8':'--'}]},
			singleSelect:false,
			frozenColumns : [[{
				title : 'id',
				field:'id',
				checkbox : true
			}]],
		    columns:[[
					{
					title:'标题',
					field:'col1',
					width:100,
					sortable:true
				    },
					{
					title:'店铺名称',
					field:'col2',
					width:100
					},{
					title:'店铺地址',
					field:'col3',
					width:100
					},{
					title:'内容',
					field:'col4',
					width:150
					},{
					title:'添加时间',
					field:'col5',
					width:200
					},{
					title:'添加人员',
					field:'col6',
					width:100
					},{
					title:'状态',
					field:'col7',
					width:80,
					formatter:function(value,rec,index){
						 return value==0? "未处理":"已处理";
						}
					},{
					title:'备注',
					field:'col8',
					width:80
					},{
					title:'操作',
					field:'opt',
					width:100,
					formatter:function(value,rec,index){
						var str='<a href="javascript:;" class="jsEdit" >编辑</a> | <a data-id='+rec.id+' href="javascript:;" class="jsDel">删除</a>';
						return str;
					}
					}
		]],
		onLoadSuccess:function(){
			//编辑
			$('.jsEdit').click(function(){
				tbgrid.datagrid('unselectAll');
				tbgrid.datagrid('selectRow',$(this).closest('tr').index());
				var rows = tbgrid.datagrid('getSelected');
				edit(rows);
				return false;
			});
			
			//删除
			$('.jsDel').click(function(){
				tbgrid.datagrid('unselectAll');
				tbgrid.datagrid('selectRow',$(this).closest('tr').index());
				var id=$(this).attr('data-id');
				del(id);
				return false;
			});
		
		}

	});

}


function add(){
	myform=$('#myForm');
	myform.form("clear"); //清空表单
	ygDialog({
		title:'添加假店店铺',
		target:$('#myFormPanel'),
		width:600,
		height:350,
		 buttons:[{
			text:'确认',
			handler:function(dialog){
				save(dialog)
			}
		},{
				text:'取消',
				handler:function(dialog){
					dialog.close();
				}
		}]
	});
}


function del(id){
	if(id.length<=0){
		showError('请选择需要删除的项目！');
		return;
	}
	showConfirm('确认删除吗？',function(){					 
				showSuc('删除成功！'+id);
				tbgrid.datagrid('deleteRow',0);
				$('#tbList').datagrid('reload');
				  
	});
}


function edit(rows){
	myform=$('#myForm');
	$('input[name=title]').val(rows.col1);
	$('input[name=pubTime]').val(rows.col2);
	$('input[name=url]').val(rows.col3);
	$('#status').combobox('setValue',rows.col7);
	ygDialog({
		title:'编辑店铺',
		target:$('#myFormPanel'),
		width:600,
		height:350,
		 buttons:[{
			text:'确认',
			handler:function(dialog){
				save(dialog);
			}
		},{
				text:'取消',
				handler:function(dialog){
					dialog.close();
				}
		}]
	});	
}

function save(dialog){
	myform.form({
	url:'form3_proc.php',
	onSubmit:function(){
		return $(this).form('validate');
	},
	success:function(data){
		showSuc('操作成功！');
		var data = myform.form("getData");
		console.log(data);
		dialog.close();
	}
	});
	myform.submit();	
}


</script>
</head>

<body class="easyui-layout">
<div data-options="region:'north',border:false" class="toolbar-region">
    <div id="toolbar">
    </div>
</div>
<div  data-options="region:'center',border:false">
    <!--subLayout start-->
    <div class="easyui-layout" data-options="fit:true" id="subLayout">
        <!--搜索start-->
        <div data-options="region:'north',border:false" >
            <div class="search-div">
                <form name="searchForm" id="searchForm" action="" method="post" >
                    <table class="search-tb" >
                        <col width="80" />
                        <col/>
                        <col width="80" />
                        <col/>
                        <col width="80" />
                        <col/>
                        <tbody>
                            <tr>
                                <th>标题：</th>
                                <td><input class="ipt" /></td>
                                <th>店铺名称：</th>
                                <td><input class="ipt" /></td>
                                <th>操作员：</th>
                                <td><input class="ipt" /> <a class="easyui-linkbutton ml10" id="SearchBtn">搜索</a></td>
                            </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
        <!--搜索end--> 
        <!--列表-->
        <div data-options="region:'center',border:false">
            <table id="tbList">
            </table>
        </div>
    </div>
    <!--subLayout end-->
</div>

<!--新增表单-->
<div id="myFormPanel" class="easyui-dialog" data-options="closed:true">
    <div class="pd10">
        <form id="myForm" method="post" novalidate>
            <table class="form-tb">
                <tbody>
                    <tr>
                        <th  style="width:120px;"><em class="cred">*</em> 标题：</th>
                        <td><input name="title" type="text" class="ipt easyui-validatebox" data-options="required:true,missingMessage:'标题不能为空！'" /></td>
                    </tr>
                    <tr>
                        <th><em class="cred">*</em> 店铺名称：</th>
                        <td><input name="title" type="text" class="ipt easyui-validatebox" data-options="required:true,missingMessage:'店铺名称不能为空！'" /></td>
                    </tr>
                    <tr>
                        <th><em class="cred">*</em>店铺网址：</th>
                        <td><input name="url" type="text" class="ipt easyui-validatebox" validType="url" data-options="required:true,missingMessage:'店铺网址不能为空！'" /></td>
                    </tr>
                    <tr>
                        <th>状态：</th>
                        <td><select id="status"  class="easyui-combobox easyui-validatebox"  data-options="required:true,missingMessage:'请选择状态！',width:160">
                                <option value="0">未处理</option>
                                <option value="1">已处理</option>
                            </select></td>
                    </tr>
                    <tr>
                        <th class="vtop">内容：</th>
                        <td><textarea class="ipt"  style="width:350px;height:80px;"></textarea></td>
                    </tr>
                </tbody>
            </table>
        </form>
    </div>
</div>
<!--新增表单结束-->

</body>
</html>
